<template>
	<view>
		<u-navbar title="个人中心" :is-back="false" titleColor="#fff" :border-bottom="false"
			:background="{ background: ' #1d336f' }"></u-navbar>
		<view v-if="userInfo != ''" class=" pr20 pl20 dis-flex flex-align-center" style="background: #1d336f;height: 200rpx;">
			<image :src="userInfo.avatarUrl" mode="" style="width: 120rpx;height: 120rpx;border-radius: 200rpx;"></image>
			<view class=" m15 c-fff fs16">{{userInfo.nickName}}</view>
		</view>
		<view v-else class=" pr20 pl20 dis-flex flex-align-center" style="background: #1d336f;height: 200rpx;">
			<image src="../../static/tou.png" mode="" style="width: 120rpx;height: 120rpx;border-radius: 200rpx;"></image>
			<view @click="login" class=" ml15 c-fff fs16">微信用户</view>
		</view>
		<view class="mr15 ml15 br5 bg-fff mt20" style="height: 290rpx;">
			<view class="dis-flex flex-between pr15 pl15  bb " style="height: 100rpx;line-height: 100rpx;">
				<view class="fw600 fs15">我的预约单</view>
				<view @click="godingdan(0)" class="c-999 fs13">查看全部订单<text v-if="order_num">({{order_num}})</text></view>
			</view>
			<view class=" dis-flex ">
				<view @click="godingdan(1)" class="wd25 center pt20">
					<image src="../../static/dfk.png" mode="" style="width: 60rpx;height: 60rpx;"></image>
					<view class="mt5 fs13">待付款</view>
				</view>
				<view @click="godingdan(2)" class="wd25 center pt20">
					<image src="../../static/yyz.png" mode="" style="width: 60rpx;height: 60rpx;"></image>
					<view class="mt5 fs13">已预约</view>
				</view>
				<view @click="godingdan(3)" class="wd25 center pt20">
					<image src="../../static/jcz.png" mode="" style="width: 60rpx;height: 60rpx;"></image>
					<view class="mt5 fs13">检测中</view>
				</view>
				<view @click="godingdan(4)" class="wd25 center pt20">
					<image src="../../static/yjc.png" mode="" style="width: 60rpx;height: 60rpx;"></image>
					<view class="mt5 fs13">已检测</view>
				</view>
			</view>
		</view>
		<view v-if="is_staff == 1" class="mr15 ml15 br5 bg-fff mt20" style="height: 290rpx;">
			<view class="dis-flex flex-between pr15 pl15  bb " style="height: 100rpx;line-height: 100rpx;">
				<view class="fw600 fs15">工具</view>
				<view @click="goyuangongdingdan(2)" class="c-999 fs13" v-if="jc_order_num">已预约订单<text >({{jc_order_num}})</text></view>
			</view>
			<view class=" dis-flex ">
				<view @click="goyuangongdingdan(0)" class="wd25 center pt20">
					<image src="../../static/gldd.png" mode="" style="width: 60rpx;height: 60rpx;"></image>
					<view class="mt5 fs13">订单管理</view>
				</view>

			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo: [],
				is_staff: 0 ,//是否是员工 0不是 1是
				order_num:0,//用户订单总数
				jc_order_num:0//员工需检测订单数量
			}
		},
		onLoad() {
			if (uni.getStorageSync('userInfo')) {
				this.userInfo = uni.getStorageSync('userInfo');
			}
			this.init()
			this.orderallnum()
			this.yuanordernum()
		},
		methods: {
			init(){
				//获取用户信息
				var json={
					uid:uni.getStorageSync('uid'),
				}
				this.$http.post(this.$config.UrlPostuserInfo, json).then((res) => {
					if (res.status == 1) {
						this.is_staff = res.data.is_staff
					} 
				})
			},
			//用户订单总数
			orderallnum(){
				var json={
					uid:uni.getStorageSync('uid'),
					tag:0
				}
				this.$http.post(this.$config.UrlPostorderList, json).then((res) => {
					if (res.status == 1) {
						this.order_num = res.data.length
					} 
				})
			},
			//员工已预约订单
			yuanordernum(){
				var json={
					uid:uni.getStorageSync('uid'),
					tag:2
				}
				this.$http.post(this.$config.UrlPoststaffOrder, json).then((res) => {
					if (res.status == 1) {
						this.jc_order_num = res.data.length
					} 
				})
			},
			godingdan(index) {
				this.$api.openWindow("/pages/order/order?tag="+index)
			},
			goyuangongdingdan(tag){
				this.$api.openWindow("/pages/yuan_order/yuan_order?tag="+tag)
			},
			login() {
				var that = this
				uni.getUserProfile({
					lang: 'zh_CN',
					desc: '登录2',
					success: (res) => {
						that.userInfo = res.userInfo;
						uni.setStorageSync('userInfo', res.userInfo);
						//提交用户名称/头像
						var json={
							uid:uni.getStorageSync('uid'),
							name:res.userInfo.nickName,
							img:res.userInfo.avatarUrl,
						}
						this.$http.post(this.$config.UrlPostupdateUser, json).then((res) => {
							if (res.status == 1) {
							} 
						})
						this.$api.toast("授权成功")
					}
				});
				
			}
		}
	}
</script>

<style>
	page {
		background: #f1f1f1;
		color: #333333;
	}
</style>
